/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * JF_ModificarBeneficiario.java
 *
 * Created on 15-mar-2010, 2:23:40
 */

package cliente.presentacion.administrador.beneficiarios;

import cliente.negocio.Controlador_Gestion_Beneficiario;
import java.awt.Toolkit;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JOptionPane;
import server.dominio.Beneficiario;
import server.dominio.Medico;

/**
 *
 * @author tpaxle
 */
public class JF_ModificarBeneficiario extends javax.swing.JFrame implements iJF_ModificarBeneficiario {
    private Controlador_Gestion_Beneficiario C_Admin;
    private Beneficiario beneficairiomostrado;
    private final int anopediatra;
    private boolean pediatraactivo= false;
    /** Creates new form JF_ModificarBeneficiario */
    public JF_ModificarBeneficiario(Controlador_Gestion_Beneficiario C_Admin) {
        initComponents();
        this.setLocation((int)Toolkit.getDefaultToolkit().getScreenSize().getWidth()/4,(int)Toolkit.getDefaultToolkit().getScreenSize().getHeight()/6);
        this.C_Admin= C_Admin;
        Calendar calendario = Calendar.getInstance();
        calendario.setTime(new Date());
        anopediatra= calendario.get(Calendar.YEAR)-14;
        
        this.iniciarmedicos(0);
        this.iniciaragnos();


    }



    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel4 = new javax.swing.JPanel();
        jLabel4 = new javax.swing.JLabel();
        jLayeredPane5 = new javax.swing.JLayeredPane();
        jLabel19 = new javax.swing.JLabel();
        jComboBox7 = new javax.swing.JComboBox();
        jLabel20 = new javax.swing.JLabel();
        jTextField_NIF = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jTextField_NSS = new javax.swing.JTextField();
        jPanel5 = new javax.swing.JPanel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jComboBox1 = new javax.swing.JComboBox();
        jTextField_med_Nif = new javax.swing.JTextField();
        jTextField_medi_Nombre = new javax.swing.JTextField();
        jTextField_medi_apellidos = new javax.swing.JTextField();
        jLayeredPane6 = new javax.swing.JLayeredPane();
        jLabel21 = new javax.swing.JLabel();
        jLabel22 = new javax.swing.JLabel();
        jLabel23 = new javax.swing.JLabel();
        jLabel24 = new javax.swing.JLabel();
        jLabel25 = new javax.swing.JLabel();
        jTextField_email = new javax.swing.JTextField();
        jLabel26 = new javax.swing.JLabel();
        jTextField_Nombre = new javax.swing.JTextField();
        jTextField_Apellido = new javax.swing.JTextField();
        jTextField_domicilio = new javax.swing.JTextField();
        jTextField_telefonofijo = new javax.swing.JTextField();
        jTextField_telmovil = new javax.swing.JTextField();
        jLabel27 = new javax.swing.JLabel();
        jComboBox2 = new javax.swing.JComboBox();
        jComboBox3 = new javax.swing.JComboBox();
        jComboBox8 = new javax.swing.JComboBox();
        jButton_ok = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jLabel4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/1268112229_list-add-user.png"))); // NOI18N

        jLayeredPane5.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createTitledBorder(""), "Datos de usuario"));

        jLabel19.setText("Medico:");
        jLabel19.setBounds(10, 110, 50, 20);
        jLayeredPane5.add(jLabel19, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jComboBox7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBox7ActionPerformed(evt);
            }
        });
        jComboBox7.setBounds(70, 110, 180, 26);
        jLayeredPane5.add(jComboBox7, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel20.setText("NIF:");
        jLabel20.setBounds(20, 70, 40, 20);
        jLayeredPane5.add(jLabel20, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jTextField_NIF.setBounds(70, 70, 180, 20);
        jLayeredPane5.add(jTextField_NIF, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel5.setText("NSS");
        jLabel5.setBounds(20, 30, 40, 20);
        jLayeredPane5.add(jLabel5, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jTextField_NSS.setBounds(70, 30, 180, 26);
        jLayeredPane5.add(jTextField_NSS, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder("Datos Medico Cabecera"));

        jLabel6.setText("Nif");

        jLabel7.setText("Especialidad");

        jLabel8.setText("Nombre");

        jLabel9.setText("Apellidos");

        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Cabecera", "Pediatría", "Urología", "Cirugía", "Neurología", "Ginecología", "Digestivo", "Oftalmología" }));
        jComboBox1.setEnabled(false);

        jTextField_med_Nif.setEditable(false);

        jTextField_medi_Nombre.setEditable(false);

        jTextField_medi_apellidos.setEditable(false);

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel7))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup()
                        .addGap(76, 76, 76)
                        .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(12, 12, 12)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jTextField_med_Nif, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 103, Short.MAX_VALUE)
                    .addComponent(jComboBox1, 0, 103, Short.MAX_VALUE))
                .addGap(18, 18, 18)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel8)
                    .addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jTextField_medi_Nombre, javax.swing.GroupLayout.DEFAULT_SIZE, 117, Short.MAX_VALUE)
                    .addComponent(jTextField_medi_apellidos, javax.swing.GroupLayout.DEFAULT_SIZE, 117, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextField_medi_Nombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextField_med_Nif, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel8)
                    .addComponent(jLabel6))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextField_medi_apellidos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7)
                    .addComponent(jLabel9))
                .addGap(28, 28, 28))
        );

        jLayeredPane6.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createTitledBorder(""), "Datos personales"));

        jLabel21.setText("Nombre:");
        jLabel21.setBounds(20, 40, 70, 20);
        jLayeredPane6.add(jLabel21, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel22.setText("Apellidos:");
        jLabel22.setBounds(20, 70, 70, 20);
        jLayeredPane6.add(jLabel22, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel23.setText("Domicilio:");
        jLabel23.setBounds(20, 100, 70, 20);
        jLayeredPane6.add(jLabel23, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel24.setText("Telf. Fijo:");
        jLabel24.setBounds(20, 130, 70, 20);
        jLayeredPane6.add(jLabel24, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel25.setText("Telf. Movil:");
        jLabel25.setBounds(230, 130, 70, 20);
        jLayeredPane6.add(jLabel25, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jTextField_email.setBounds(100, 160, 330, 20);
        jLayeredPane6.add(jTextField_email, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel26.setText("Email:");
        jLabel26.setBounds(20, 160, 60, 20);
        jLayeredPane6.add(jLabel26, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jTextField_Nombre.setBounds(100, 40, 140, 20);
        jLayeredPane6.add(jTextField_Nombre, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jTextField_Apellido.setBounds(100, 70, 330, 20);
        jLayeredPane6.add(jTextField_Apellido, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jTextField_domicilio.setBounds(100, 100, 330, 20);
        jLayeredPane6.add(jTextField_domicilio, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jTextField_telefonofijo.setBounds(100, 130, 110, 20);
        jLayeredPane6.add(jTextField_telefonofijo, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jTextField_telmovil.setBounds(310, 130, 120, 20);
        jLayeredPane6.add(jTextField_telmovil, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel27.setText("Fecha de nacimiento:");
        jLabel27.setBounds(20, 200, 130, 20);
        jLayeredPane6.add(jLabel27, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jComboBox2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31" }));
        jComboBox2.setBounds(160, 200, 70, 26);
        jLayeredPane6.add(jComboBox2, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jComboBox3.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre" }));
        jComboBox3.setBounds(230, 200, 120, 26);
        jLayeredPane6.add(jComboBox3, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jComboBox8.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        jComboBox8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBox8ActionPerformed(evt);
            }
        });
        jComboBox8.setBounds(350, 200, 78, 26);
        jLayeredPane6.add(jComboBox8, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jButton_ok.setText("Modificar");
        jButton_ok.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_okActionPerformed(evt);
            }
        });

        jButton1.setText("Cancelar");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGap(243, 243, 243)
                        .addComponent(jButton1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton_ok, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel4Layout.createSequentialGroup()
                                .addContainerGap()
                                .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .addGroup(jPanel4Layout.createSequentialGroup()
                                .addGap(37, 37, 37)
                                .addComponent(jLabel4)
                                .addGap(28, 28, 28)
                                .addComponent(jLayeredPane5, javax.swing.GroupLayout.PREFERRED_SIZE, 266, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel4Layout.createSequentialGroup()
                                .addContainerGap()
                                .addComponent(jLayeredPane6, javax.swing.GroupLayout.DEFAULT_SIZE, 444, Short.MAX_VALUE)))
                        .addGap(286, 286, 286)))
                .addContainerGap())
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGap(26, 26, 26)
                        .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 138, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLayeredPane5, javax.swing.GroupLayout.PREFERRED_SIZE, 163, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLayeredPane6, javax.swing.GroupLayout.PREFERRED_SIZE, 242, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton_ok, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, 465, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jComboBox7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox7ActionPerformed
          this.iniciarmedico(jComboBox7.getSelectedIndex());
}//GEN-LAST:event_jComboBox7ActionPerformed

    private void jButton_okActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_okActionPerformed
        String [] datos= obtenercampos();
        if(camposobligatorios())
            C_Admin.modificarbeneficiario(datos);
        else{
            JOptionPane.showMessageDialog(null, "Introduzca todos los datos obligatorios", "Error al introducir datos", JOptionPane.ERROR_MESSAGE);
        }

    }//GEN-LAST:event_jButton_okActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        this.dispose();
}//GEN-LAST:event_jButton1ActionPerformed

    private void jComboBox8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox8ActionPerformed
          
        if(Integer.parseInt((String) jComboBox8.getSelectedItem())>anopediatra){
pediatraactivo= true;
            this.iniciarmedicos(2);
            
        }else{
            pediatraactivo= false;
            this.iniciarmedicos(1);
        }
    }//GEN-LAST:event_jComboBox8ActionPerformed

 

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton_ok;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JComboBox jComboBox2;
    private javax.swing.JComboBox jComboBox3;
    private javax.swing.JComboBox jComboBox7;
    private javax.swing.JComboBox jComboBox8;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel23;
    private javax.swing.JLabel jLabel24;
    private javax.swing.JLabel jLabel25;
    private javax.swing.JLabel jLabel26;
    private javax.swing.JLabel jLabel27;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JLayeredPane jLayeredPane5;
    private javax.swing.JLayeredPane jLayeredPane6;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JTextField jTextField_Apellido;
    private javax.swing.JTextField jTextField_NIF;
    private javax.swing.JTextField jTextField_NSS;
    private javax.swing.JTextField jTextField_Nombre;
    private javax.swing.JTextField jTextField_domicilio;
    private javax.swing.JTextField jTextField_email;
    private javax.swing.JTextField jTextField_med_Nif;
    private javax.swing.JTextField jTextField_medi_Nombre;
    private javax.swing.JTextField jTextField_medi_apellidos;
    private javax.swing.JTextField jTextField_telefonofijo;
    private javax.swing.JTextField jTextField_telmovil;
    // End of variables declaration//GEN-END:variables

    public void mostrar(boolean b) {
        this.setVisible(true);
    }

    public void mostrabeneficiario(Beneficiario beneficiario) {
         if (beneficiario != null) {
            beneficairiomostrado= beneficiario;

            jTextField_Nombre.setText(beneficiario.getNombre());
            jTextField_NIF.setText(beneficiario.getNif());
            jTextField_Apellido.setText(beneficiario.getApellidos());
            jTextField_domicilio.setText(beneficiario.getDomicilio());
            jTextField_email.setText(beneficiario.getEmail());
            jTextField_telefonofijo.setText("" + beneficiario.getTelefFijo());
            jTextField_telmovil.setText("" + beneficiario.getTelefMovil());
            
            //Modificar con calendarios
            Calendar fecha = Calendar.getInstance();
            fecha.setTime(beneficiario.getFechaNacimiento());
            
            jComboBox8.setSelectedIndex(fecha.get(Calendar.YEAR)-1900);
            //Mes
            jComboBox3.setSelectedIndex(fecha.get(Calendar.MONTH));
            jComboBox2.setSelectedIndex(fecha.get(Calendar.DAY_OF_MONTH));


            jTextField_NSS.setText(beneficiario.getNss());
            jTextField_med_Nif.setText(beneficiario.getMedico().getUsuario().getNif());
            jTextField_medi_Nombre.setText(beneficiario.getMedico().getUsuario().getNombre());
            jTextField_medi_apellidos.setText(beneficiario.getMedico().getUsuario().getApellidos());
            jComboBox1.setSelectedIndex(beneficiario.getMedico().getIdMedicoPk()-1);
          
            this.setVisible(true);

        } else {
            this.setVisible(false);
           // controlador.log("Error, el usuario n0 ha sido pasado");
        }

    }
  private void iniciaragnos() {
        String [] datos= new String[160];
        for(int i=0; i<160; i++){
            datos[i]= ""+ (1900 +i);
        }
        jComboBox8.setModel(new DefaultComboBoxModel(datos));
    }
    private void iniciarmedicos(int tipo) {

        Medico medico;
        ArrayList<server.dominio.Medico> listamedicos;
        listamedicos= C_Admin.getListamedicos();
        ArrayList<String> listadatos= new ArrayList<String>();
        for(int i=0; i<listamedicos.size(); i++){
            if(listamedicos.get(i).getIdTipoMedico()== tipo || tipo == 0){
                listadatos.add(listamedicos.get(i).getUsuario().getNif());
            }
        }
         if(listadatos.size()>0){
            jComboBox7.setModel(new DefaultComboBoxModel(listadatos.toArray()));
            jTextField_med_Nif.setText(listamedicos.get(0).getUsuario().getNif());
            jTextField_medi_Nombre.setText(listamedicos.get(0).getUsuario().getNombre());
            jTextField_medi_apellidos.setText(listamedicos.get(0).getUsuario().getApellidos());
            jComboBox1.setSelectedIndex(listamedicos.get(0).getIdTipoMedico()-1);
        }else{
            Object [] ob= {};
            jComboBox7.setModel(new DefaultComboBoxModel(ob));
            jComboBox1.setSelectedIndex(-1);
            jTextField_med_Nif.setText("");
            jTextField_medi_Nombre.setText("");
            jTextField_medi_apellidos.setText("");

        }
        }

    private int buscarindex(String nif) {
        int resultado=-1;
        for(int i=0; i<jComboBox7.getItemCount(); i++){
            if(jComboBox7.getItemAt(i).equals(nif)){
                return i;
            }
        }
        return resultado;
    }

   private void iniciarmedico(int nmedico){
        Medico medico = C_Admin.getListamedicos().get(nmedico);

        jTextField_med_Nif.setText(medico.getUsuario().getNif());
        jTextField_medi_Nombre.setText(medico.getUsuario().getNombre());
        jTextField_medi_apellidos.setText(medico.getUsuario().getApellidos());
        jComboBox1.setSelectedIndex(medico.getIdTipoMedico()-1);
    }

    private String [] obtenercampos(){
            String mes,dia;
            String [] resultado;
            if(jComboBox3.getSelectedIndex()<9){
                mes= "0"+(jComboBox3.getSelectedIndex()+1);
            }else{
                mes= ""+(jComboBox3.getSelectedIndex()+1);
            }
            if(jComboBox2.getSelectedIndex()<9){
                dia= "0"+(jComboBox2.getSelectedIndex()+1);
            }else{
                dia= ""+(jComboBox2.getSelectedIndex()+1);
            }
            String tipomedico= "";
            String centro= "";
            String fechanacimiento= jComboBox8.getSelectedItem().toString() + "-" + mes + "-"+dia;
            String [] informacion= {jTextField_NSS.getText(),jTextField_NIF.getText(), jTextField_Nombre.getText(), jTextField_Apellido.getText(), jTextField_domicilio.getText(), jTextField_email.getText(), jTextField_telefonofijo.getText(), jTextField_telmovil.getText(), fechanacimiento, ""+jComboBox7.getSelectedItem()};



            return informacion;
            
    }

    public void error(int opcion) {
        switch(opcion){
            case 1:
                JOptionPane.showMessageDialog(null, "No se han modificado los datos", "Error al introducir datos", JOptionPane.ERROR_MESSAGE);
                break;
            case 2:
                JOptionPane.showMessageDialog(null, "El NSS o Nif introducido ya es utilizado por otro usuario.", "Error al introducir datos", JOptionPane.ERROR_MESSAGE);
                break;
            case 3:
                JOptionPane.showMessageDialog(null, "Problemas en la sincronizacion, por favor reinicie la aplicacion y si no funciona llame al servicio tecnico", "Problema funcionamiento", JOptionPane.ERROR_MESSAGE);
                break;
            case 4:
                JOptionPane.showMessageDialog(null, "Es posible que el usuario haya sido modificado en otro administrador", "Problema funcionamiento", JOptionPane.ERROR_MESSAGE);
                break;
        }
    }

    public void cerrar() {
        this.dispose();
    }

     private boolean camposobligatorios() {
        boolean solucion= true;
        solucion= solucion && jTextField_NIF.getText().length()>0 && jTextField_Nombre.getText().length()>0;
        solucion= solucion && jTextField_Apellido.getText().length()>0 && jTextField_telefonofijo.getText().length()>0;
        solucion= solucion && jTextField_NSS.getText().length()>0 && jTextField_domicilio.getText().length()>0;
        solucion= solucion && jComboBox7.getSelectedIndex()!=-1;
        return solucion;

    }
}
